package it.irondev.appturismo.dao;

import it.irondev.appturismo.dao.example.AttractionsExample;
import it.irondev.appturismo.dao.provider.AttractionsSqlProvider;
import it.irondev.appturismo.entity.Attractions;
import it.irondev.appturismo.entity.City;
import it.irondev.appturismo.entity.Gallery;
import it.irondev.appturismo.entity.Language;

import java.util.List;

import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.DeleteProvider;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.InsertProvider;
import org.apache.ibatis.annotations.One;
import org.apache.ibatis.annotations.Options;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Result;
import org.apache.ibatis.annotations.Results;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.SelectProvider;
import org.apache.ibatis.annotations.Update;
import org.apache.ibatis.annotations.UpdateProvider;
import org.apache.ibatis.type.JdbcType;

public interface AttractionsMapper {
    @SelectProvider(type=AttractionsSqlProvider.class, method="countByExample")
    int countByExample(AttractionsExample example);

    @DeleteProvider(type=AttractionsSqlProvider.class, method="deleteByExample")
    int deleteByExample(AttractionsExample example);

    @Delete({
        "delete from Attractions",
        "where idAttraction = #{idattraction,jdbcType=INTEGER}"
    })
    int deleteByPrimaryKey(Integer idattraction);

    @Insert({
        "insert into Attractions (idAttraction, name, ",
        "description, phone, ",
        "email, website, ",
        "city, position, ",
        "type, language, ",
        "address, shortdescrption)",
        "values (#{idattraction,jdbcType=INTEGER}, #{name,jdbcType=VARCHAR}, ",
        "#{description,jdbcType=VARCHAR}, #{phone,jdbcType=VARCHAR}, ",
        "#{email,jdbcType=VARCHAR}, #{website,jdbcType=VARCHAR}, ",
        "#{city.idcity,jdbcType=INTEGER}, #{position,jdbcType=VARCHAR}, ",
        "#{type,jdbcType=INTEGER}, #{language.idlanguage,jdbcType=INTEGER}, ",
        "#{address,jdbcType=VARCHAR}, #{shortdescrption,jdbcType=VARCHAR})"
    })
	@Options(useGeneratedKeys = true, keyProperty="idAttraction")
    int insert(Attractions record);

    @InsertProvider(type=AttractionsSqlProvider.class, method="insertSelective")
    int insertSelective(Attractions record);

    @SelectProvider(type=AttractionsSqlProvider.class, method="selectByExample")
    @Results({
        @Result(column="idAttraction", property="idattraction", jdbcType=JdbcType.INTEGER, id=true),
        @Result(column="name", property="name", jdbcType=JdbcType.VARCHAR),
        @Result(column="description", property="description", jdbcType=JdbcType.VARCHAR),
        @Result(column="phone", property="phone", jdbcType=JdbcType.VARCHAR),
        @Result(column="email", property="email", jdbcType=JdbcType.VARCHAR),
        @Result(column="website", property="website", jdbcType=JdbcType.VARCHAR),
        @Result(column="position", property="position", jdbcType=JdbcType.VARCHAR),
        @Result(column="type", property="type", jdbcType=JdbcType.INTEGER),
        @Result(column="address", property="address", jdbcType=JdbcType.VARCHAR),
		@Result(column="city", property="city", javaType=City.class, one=@One(select="it.irondev.appturismo.dao.CityMapper.selectByPrimaryKey")),
		@Result(column="language", property="language", javaType=Language.class, one=@One(select="it.irondev.appturismo.dao.LanguageMapper.selectByPrimaryKey")),
		@Result(column="gallery", property="gallery", javaType=Gallery.class, one=@One(select="it.irondev.appturismo.dao.GalleryMapper.selectByPrimaryKey")),
		@Result(column="shortDescrption", property="shortdescrption", jdbcType=JdbcType.VARCHAR)
    })
    List<Attractions> selectByExample(AttractionsExample example);

    @Select({
        "select",
        "idAttraction, name, description, phone, email, website, city, position, type, ",
        "language, address, gallery, shortDescrption",
        "from Attractions",
        "where idAttraction = #{idattraction,jdbcType=INTEGER}"
    })
    @Results({
        @Result(column="idAttraction", property="idattraction", jdbcType=JdbcType.INTEGER, id=true),
        @Result(column="name", property="name", jdbcType=JdbcType.VARCHAR),
        @Result(column="description", property="description", jdbcType=JdbcType.VARCHAR),
        @Result(column="phone", property="phone", jdbcType=JdbcType.VARCHAR),
        @Result(column="email", property="email", jdbcType=JdbcType.VARCHAR),
        @Result(column="website", property="website", jdbcType=JdbcType.VARCHAR),
        @Result(column="position", property="position", jdbcType=JdbcType.VARCHAR),
        @Result(column="type", property="type", jdbcType=JdbcType.INTEGER),
        @Result(column="address", property="address", jdbcType=JdbcType.VARCHAR),
		@Result(column="city", property="city", javaType=City.class, one=@One(select="it.irondev.appturismo.dao.CityMapper.selectByPrimaryKey")),
		@Result(column="language", property="language", javaType=Language.class, one=@One(select="it.irondev.appturismo.dao.LanguageMapper.selectByPrimaryKey")),
		@Result(column="gallery", property="gallery", javaType=Gallery.class, one=@One(select="it.irondev.appturismo.dao.GalleryMapper.selectByPrimaryKey")),
		@Result(column="shortDescrption", property="shortdescrption", jdbcType=JdbcType.VARCHAR)
    })
    Attractions selectByPrimaryKey(Integer idattraction);

    @UpdateProvider(type=AttractionsSqlProvider.class, method="updateByExampleSelective")
    int updateByExampleSelective(@Param("record") Attractions record, @Param("example") AttractionsExample example);

    @UpdateProvider(type=AttractionsSqlProvider.class, method="updateByExample")
    int updateByExample(@Param("record") Attractions record, @Param("example") AttractionsExample example);

    @UpdateProvider(type=AttractionsSqlProvider.class, method="updateByPrimaryKeySelective")
    int updateByPrimaryKeySelective(Attractions record);

    @Update({
        "update Attractions",
        "set name = #{name,jdbcType=VARCHAR},",
          "description = #{description,jdbcType=VARCHAR},",
          "phone = #{phone,jdbcType=VARCHAR},",
          "email = #{email,jdbcType=VARCHAR},",
          "website = #{website,jdbcType=VARCHAR},",
          "city = #{city.idcity,jdbcType=INTEGER},",
          "position = #{position,jdbcType=VARCHAR},",
          "type = #{type,jdbcType=INTEGER},",
          "language = #{language.idlanguage,jdbcType=INTEGER},",
          "gallery = #{gallery.idgallery,jdbcType=INTEGER},",
          "address = #{address,jdbcType=VARCHAR},",
          "shortDescrption = #{shortdescrption,jdbcType=VARCHAR}",
        "where idAttraction = #{idattraction,jdbcType=INTEGER}"
    })
    int updateByPrimaryKey(Attractions record);
}